home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 351-375 / disk_351 / pdc / libsrc.lzh / LibSrc / StdIO / fclose.c < prev    next >
C/C++ Source or Header  |  1990-04-07  |  1KB  |  56 lines

  1. /*
  2.  * Libraries and headers for PDC release 3.3 (C) 1989 Lionel Hummel.
  3.  * PDC Software Distribution (C) 1989 Lionel Hummel and Paul Petersen.
  4.  * PDC I/O Library (C) 1987 by J.A. Lydiatt.
  5.  *
  6.  * This code is freely redistributable upon the conditions that this 
  7.  * notice remains intact and that modified versions of this file not
  8.  * be included as part of the PDC Software Distribution without the
  9.  * express consent of the copyright holders.  No warrantee of any
  10.  * kind is provided with this code.  For further information, contact:
  11.  *
  12.  *  PDC Software Distribution    Internet:                     BIX:
  13.  *  P.O. Box 4006             or hummel@cs.uiuc.edu            lhummel
  14.  *  Urbana, IL  61801-8801       petersen@uicsrd.csrd.uiuc.edu
  15.  */
  16.  
  17. /*  fclose.c
  18.  *
  19.  *  Close a stdio stream.
  20.  */
  21.  
  22. #include <stdio.h>
  23.  
  24. extern int _doflush();
  25.  
  26. int fclose( fp )
  27. FILE *fp;
  28. {
  29.     int result;
  30.  
  31.     result = 0;
  32.     if ( fp == NULL )
  33.         return -1;
  34.  
  35.     if ( fp->_fileflag ) {
  36.         if ( fp->_fileflag & _FILEISDIRTY )
  37.             result = _doflush( fp, -1 );
  38.         result |= close( (int)fp->_fileunit );
  39.         if ( fp->_fileflag & _FILEISDYNA )
  40.             free( fp->_filebufp );
  41.     }
  42.  
  43.     fp->_filebufp = NULL;
  44.     fp->_filecpos = NULL;
  45.     fp->_fileend  = NULL;
  46.     fp->_fileflag = 0;
  47.  
  48.     return result;
  49. }
  50.  
  51. int fflush( fp )
  52. FILE *fp;
  53. {
  54.     return(_doflush( fp, -1 ));
  55. }
  56.